

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:kmxy_base/base/base_page.dart';
import 'package:kmxy_base/page/select_check/select_check_page_state.dart';
import 'package:kmxy_base/widget/divider_kmxy.dart';

/// 多选页面
// ignore: must_be_immutable
class SelectCheckPage extends BasePage {
  SelectCheckPage({Key? key, arguments})
      : super(key: key, arguments: arguments);
  @override
  SelectCheckPageView createState() => SelectCheckPageView();
}

class SelectCheckPageView extends SelectCheckPageState {
  @override
  Widget setPageContent(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: widget.arguments?['style']['centerTitle'] ?? true,
        backgroundColor:
            widget.arguments?['style']['backgroundColor'] ?? Colors.white,
        title: Text(
          widget.arguments?['style']['title'] ?? '',
          style: TextStyle(
            color: widget.arguments?['style']['color'] ?? Colors.black,
            fontSize: widget.arguments?['style']['fontSize'] ?? 16.sp,
            fontWeight:
                widget.arguments?['style']['fontWeight'] ?? FontWeight.w700,
          ),
        ),
        actions: [
          InkWell(
            onTap: sure,
            child: Container(
              margin: EdgeInsets.only(right: 10.w),
              alignment: Alignment.center,
              child: Text(
                "确定",
                style: TextStyle(
                  color: widget.arguments?['style']['color'] ?? Colors.black,
                ),
              ),
            ),
          ),
        ],
      ),
      body: SafeArea(
        child: Column(
          children: [
            Row(
              children: [
                Expanded(
                  child: Container(
                    padding: const EdgeInsets.only(left: 10, top: 5),
                    height: 60,
                    child: TextField(
                      decoration: const InputDecoration(
                        border: InputBorder.none,
                        hintText: "请输入",
                        hintStyle: TextStyle(
                          color: Color(0x66333333),
                          fontSize: 14,
                        ),
                      ),
                      onChanged: search,
                    ),
                  ),
                ),
                Container(width: 10),
                InkWell(
                  onTap: () {},
                  child: const Icon(Icons.search_outlined),
                ),
                Container(width: 10),
              ],
            ),
            DividerKmxy(height: 1.w, color: Colors.grey[400]),
            Expanded(
              child: MediaQuery.removePadding(
                context: context,
                removeTop: true,
                child: ListView.separated(
                  separatorBuilder: (BuildContext context, int index) =>
                      DividerKmxy(height: 1.w, color: Colors.grey[400]),
                  //解决无限高度问题
                  shrinkWrap: true,
                  //禁用滑动事件
                  // physics: NeverScrollableScrollPhysics(),
                  itemCount: dataList.length,
                  itemBuilder: (BuildContext context, int index) {
                    if (dataList[index]['check'] == null) {
                      dataList[index]['check'] = false;
                    }
                    return dataList[index]['isShow']
                        ? InkWell(
                            child: Container(
                                alignment: Alignment.center,
                                padding: const EdgeInsets.all(5),
                                child: Row(
                                  mainAxisAlignment:
                                      MainAxisAlignment.spaceBetween,
                                  children: [
                                    Icon(dataList[index]['check'] == true
                                        ? Icons.check_box
                                        : Icons.check_box_outline_blank),
                                    Text(
                                      dataList[index]
                                          [widget.arguments?['name']],
                                      textAlign: TextAlign.center,
                                      style: const TextStyle(
                                          color: Colors.black, fontSize: 14),
                                    ),
                                  ],
                                )),
                            onTap: () {
                              setState(() {
                                if (dataList[index]['check'] == true) {
                                  dataList[index]['check'] = false;
                                } else {
                                  dataList[index]['check'] = true;
                                }
                              });
                              // List checkNameList = [];
                              // List checkDataList = [];
                              // for (Map data in dataList) {
                              //   if (data['check'] == true) {
                              //     checkNameList.add(data[widget.arguments?['name']]);
                              //     checkDataList.add(data);
                              //   }
                              // }
                              // onConfirm(
                              //     checkDataList,
                              //     checkNameList
                              //         .toString()
                              //         .replaceAll('[', '')
                              //         .replaceAll(']', ''));
                            },
                          )
                        : Container();
                  },
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
